package bpm.dao.impl.process;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;

import org.springframework.jdbc.core.RowMapper;

import bpm.domain.document.DocumentOwnership;

public class DocumentOwnershipMapper implements RowMapper {

	public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
		DocumentOwnership ship = new DocumentOwnership();
		
		ship.workitemId = rs.getInt("workitem_id");
		ship.documentId = rs.getString("doc_id");
		
		String ownerType = rs.getString("owner_type");
		ship.ownerType = ownerType == null ? null : DocumentOwnership.OwnerType.valueOf(ownerType);
		
		ship.ownerId = rs.getString("owner_id");
		ship.userId = rs.getString("user_id");
		
		String state = rs.getString("state");
		ship.state = state == null ? null : DocumentOwnership.State.valueOf(state);
		
		java.sql.Date createTime = rs.getDate("create_time");
		ship.createTime = createTime == null ? null : new Date(createTime.getTime());
		
		ship.setDirectString(rs.getString("direct"));
		
		java.sql.Date confirmationTime = rs.getDate("confirmation_time");
		ship.confirmationTime = confirmationTime == null ? null : new Date(confirmationTime.getTime());
		
		return ship;
	}

}
